﻿@{
    ViewBag.Title = "UserBinDingEmail";
    Layout = "~/Views/Shared/MasterView.cshtml";
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.validate.min.js"> </script>
<link type="text/css" rel="stylesheet" href="/pc/themes/base.css">
<link type="text/css" rel="stylesheet" href="/pc/themes/ceng.css">
<link type="text/css" rel="stylesheet" href="/pc/themes/Safe.css">
<link rel="stylesheet" type="text/css" href="/pc/themes/util.css" />
<script>
    function TestEmail()
    {
        var reg = /^([a-zA-Z0-9_\.\-])+@@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if ($("#Email").val()!="") {
            if (!reg.test($("#Email").val()))
            {
                $("#SEmail").html("请输入有效的邮箱");
                $("#SEmail").css("color", "red");
            }
            else {
                $("#SEmail").html("√");
                $("#SEmail").css("color", "green");
            }
        }
        else
        {
            $("#SEmail").html("请输入邮箱");
            $("#SEmail").css("color", "red");
        }

    }
    var code = 0;
    function SendEmailPwd()
    {
        $.ajax({
            url: "/SecurityCenter/GetEmailActivationCode",
            type: "post",
            data: {
                Email: $("#Email").val()
            }, success: function (mes)
            {
                code = mes;
                if (mes != 0) {
                    code = mes;
                    var btn = $("#GetPhonepwd");
                    var count = 60;
                    var resend = setInterval(function ()
                    {
                        count--;
                        if (count > 0)
                        {
                            btn.val(count + "秒后重获取");
                            $.cookie("captcha", count, { path: '/', expires: (1 / 86400) * count });
                            $("#Scode").html("激活码已发送至您的邮箱")
                            $("#Scode").css("color","grren")
                        } else {
                            clearInterval(resend);
                            btn.val("获取验证码").removeAttr('disabled style');
                            $("#Scode").html("")
                        }
                    }, 1000);
                    btn.attr('disabled', true).css('cursor', 'not-allowed');
                    Error = 0;
                }
                else {
                    alert("系统异常")
                    Error = 1;
                }
            }

        })
    }
    function TestCode()
    {
        if ($("#code").val() != "")
        {
            if ($("#code").val()==code)
            {
                $("#Scode").html("√")
                $("#Scode").css("color", "green")
            }
            else
            {
                $("#Scode").html("输入验证码不正确")
                $("#Scode").css("color", "red")
            }
        }
        else
        {
            $("#Scode").html("请输入邮箱激活码")
            $("#Scode").css("color", "grren")
        }
    }
    function PostUserEmail()
    {
        if ($("#Email").val() != "") {
            if (!reg.test($("#Email").val())) {
                $("#SEmail").html("请输入有效的邮箱");
                $("#SEmail").css("color", "red");
            }
            else
            {
                if ($("#code").val() != "") {
                    if ($("#code").val() == code) {
                        $.post("/SecurityCenter/SendUserEmail", { Email: $("#Email").val() }, function (mes) {
                            if (mes != 0) {

                            }
                            else {

                            }
                        })
                    }
                    else {
                        $("#Scode").html("输入验证码不正确")
                        $("#Scode").css("color", "red")
                    }
                }
                else {
                    $("#Scode").html("请输入邮箱激活码")
                    $("#Scode").css("color", "grren")
                }
            }
        }
        else {
            $("#SEmail").html("请输入邮箱");
            $("#SEmail").css("color", "red");
        }
    }
</script>
<table align="center">

</table>
<div class="content" id="hongman">
    <div class="Bind">
        <style type="text/css">
            .span_lf {
                margin: 20px 0 20px 150px;
            }

                .span_lf .txt_180 {
                    width: 322px;
                }

                .span_lf .txt_80 {
                    width: 178px;
                }

                .span_lf .but_jb {
                    margin-left: 5px;
                    width: 140px;
                }
        </style>
        <div  class="path_safe"><span><a href="/SecurityCenter/UserBinDingEmail">安全中心</a></span><em>&gt;</em><span>绑定邮箱</span></div>
        <div class="clear"></div>
        <div style="" class="span_lf">
            <ul>
                <li><span class="sp_1">邮箱账号：</span>
                    <span>&nbsp;<input type="text" onblur="TestEmail()" id="Email" value="" size="28"  placeholder="请输入有效的邮箱地址" />
                    </span><span id="SEmail"></span></li>
                     <li><span class="sp_1">激活码：</span>
                    <span>&nbsp;<input type="text" id="code" name="code" class="txt_80" onblur="TestCode()" />
                    <input type="button" class="" id="GetPhonepwd" value="获取激活码" onclick="SendEmailPwd()" /></span><span id="SCode">
                    </span></li>
                <li id="tip"></li>
            </ul>
            <div class="clear"></div>
            <p style=" margin:10px 0 0 150px;"><input type="button" id="ConmitBtn" value="确  定" class="Flat_but" onclick="BinDingPhone()" /></p>
            <div class="clear"></div>
        </div>
    </div>
</div>